package com.ld.security.common.quartz.modules.job.api;

import com.ld.security.common.mybatis.base.po.IdsPo;
import com.ld.security.common.mybatis.base.vo.DataVo;
import com.ld.security.common.quartz.modules.job.entity.JobTaskEntity;
import com.ld.security.common.quartz.modules.job.service.IJobTaskService;
import com.ld.security.common.tomcat.anno.AjaxLogKey;
import com.ld.security.common.tomcat.base.api.SuperApi;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/jobTask")
@Api(tags = "任务管理")
public class JobTaskApi extends SuperApi<JobTaskEntity> {

    @Autowired
    IJobTaskService iJobTaskService;

    @AjaxLogKey
    @ApiOperation("批量运行任务")
    @RequestMapping(value = "/runTask",method = RequestMethod.POST)
    public DataVo runTask(@RequestBody IdsPo po){
        int total = iJobTaskService.runTask(po.getIds());
        return DataVo.ofMsg("成功运行任务"+total+"个");
    }

    @AjaxLogKey
    @ApiOperation("批量停止任务")
    @RequestMapping(value = "/stopTask",method = RequestMethod.POST)
    public DataVo stopTask(@RequestBody IdsPo po){
        int total = iJobTaskService.stopTask(po.getIds());
        return DataVo.ofMsg("成功停止任务"+total+"个");
    }

}
